package com.liming.admin.controller;

import com.liming.common.pojo.dto.shop.ShopAddOrUpdateDTO;
import com.liming.common.pojo.dto.shop.ShopPageQuery;
import com.liming.common.pojo.vo.PageVO;
import com.liming.common.pojo.vo.shop.ShopVO;
import com.liming.common.result.LMResult;
import com.liming.shop.client.ShopClient;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author liming
 * @date 2025/3/9
 */
@Slf4j
@RestController
@AllArgsConstructor
@Tag(name = "商店接口-Web")
@RequestMapping("/admin/shop")
public class ShopController {

    private final ShopClient shopClient;

    @Operation(
            summary = "分页",
            responses = {
                    @ApiResponse(responseCode = "1", description = "获取成功", content = {
                            @Content(mediaType = "application/json", schema = @Schema(implementation = ShopVO.class))
                    })
            }
    )
    @GetMapping
    public LMResult<PageVO<ShopVO>> page(ShopPageQuery shopPageQuery) {
        return LMResult.success(shopClient.page(shopPageQuery));
    }

    @Operation(summary = "添加")
    @PostMapping
    public LMResult<Boolean> add(@RequestBody ShopAddOrUpdateDTO shopAddOrUpdateDTO) {
        return LMResult.success(shopClient.add(shopAddOrUpdateDTO));
    }

    @Operation(summary = "修改")
    @PutMapping
    public LMResult<Boolean> update(@RequestBody ShopAddOrUpdateDTO shopAddOrUpdateDTO) {
        return LMResult.success(shopClient.update(shopAddOrUpdateDTO));
    }

    @Operation(summary = "删除")
    @DeleteMapping("{id}")
    public LMResult<Boolean> delete(@PathVariable Long id) {
        return LMResult.success(shopClient.delete(id));
    }
}
